package com.quanyan.stadium.web.admin;

import com.quanyan.api.APIResponse;
import com.quanyan.stadium.biz.redis.GradeIntegralCacheDao;
import com.quanyan.stadium.service.GradeIntegralService;
import com.quanyan.stadium.service.StadiumIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author dongshenglin
 * @date 2016/6/24  16:42
 */

@RestController
@RequestMapping("/admin/api/stadium/gradeIntegral")
public class UserGradeIntegralController {

    @Autowired
    private GradeIntegralCacheDao gradeIntegralCacheDao;

    @Autowired
    private GradeIntegralService gradeIntegralService;

    @Autowired
    private StadiumIndexService stadiumIndexService;

    /**
     *  刷新某个用户评级积分信息
     */
    @RequestMapping(value = "/reflushUserGrade",method = RequestMethod.POST)
    public APIResponse<?> reflushUserGrade(@RequestBody Map<String, Object> map, HttpServletRequest request){
        gradeIntegralCacheDao.clearUserGradeInfo((Integer) map.get("uid"), (Integer) map.get("categoryId"));
        return APIResponse.returnSuccess();
    }

    /**
     *  测试评级积分
     */
    @RequestMapping(value = "/getUserGrade",method = RequestMethod.POST)
    public APIResponse<?> getUserGrade(@RequestBody Map<String, Object> map, HttpServletRequest request){
        if(null == map.get("uid") || null == map.get("categoryId")){
            return  APIResponse.returnFail("参数不合法");
        }
        return APIResponse.returnSuccess(gradeIntegralService.getUserGradeInfo((Integer)map.get("uid"),(Integer)map.get("categoryId")));
    }

    /**
     * 测试运动场首页
     */
    @RequestMapping(value = "/getUserInfo",method = RequestMethod.POST)
    public APIResponse<?> getUserInfo(@RequestBody Map<String, Object> map, HttpServletRequest request){
        if(null == map.get("uid") || null == map.get("categoryId")){
            return  APIResponse.returnFail("参数不合法");
        }
        return APIResponse.returnSuccess(stadiumIndexService.getUserGradeIntegral((Integer) map.get("uid"), (Integer) map.get("categoryId")));
    }

}
